package com.gxa.controller.discrepancy;

import java.util.Date;

import com.gxa.common.utils.R;
import com.gxa.entity.discrepancy.Device;
import com.gxa.entity.discrepancy.DeviceLog;
import com.gxa.entity.discrepancy.search.DeviceLogSearchMap;
import com.gxa.service.discrepancy.DeviceLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

import static com.gxa.common.utils.R.error;
import static com.gxa.common.utils.R.ok;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author yjl
 * @since 2022-10-12 11:43:53
 */
@Api(tags = "门禁管理--->设备日志")
@RestController
@RequestMapping("/device-log")
public class DeviceLogController {

    @Autowired
    private DeviceLogService service;

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("设备日志列表接口")
    @GetMapping("/list")
    public R queryAll(DeviceLogSearchMap map) {

        return ok("successs").put("data", service.queryByPage(map));
    }

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("新增设备日志接口")
    @PostMapping("/add")
    public R add(@RequestBody DeviceLog device) {
        if (service.save(device)) {

            return ok("add success");
        }
        return error("添加失败！");
    }

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("删除设备接口")
    @DeleteMapping("/del/{id}")
    public R del(@PathVariable("id") Integer id) {
        if(service.removeById(id)){
            return ok("删除失败！");
        }
        return error("del error");
    }


    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("编辑设备日志接口")
    @PutMapping("/edit")
    public R edit(@RequestBody DeviceLog device) {
        if(service.updateById(device)){
            return ok("更新成功！");
        }
        return error("edit error");
    }
}
